using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input.Touch;
using BlawkayMobileLibrary;

namespace Bounce
{
    public class Menu : Screen
    {

        public Menu(GamePage oPage)
            : base()
        {
            GamePage = oPage;
        }

        #region Screen Methods

        public override void Initialize(ContentManager oContentManager, GraphicsDevice oDevice)
        {
            base.Initialize(oContentManager, oDevice);

            Texture_Button = oContentManager.Load<Texture2D>("Circle");
            Font = oContentManager.Load<SpriteFont>("TestFont");

            Buttons = new List<Button>();
            Buttons.Add(
                new Button("Many Balls", new Vector2(100, 200), 40.0f, Texture_Button));
            Buttons.Add(
                new Button("Aim It", new Vector2(300, 200), 40.0f, Texture_Button));
            Buttons.Add(
                new Button("Putt Putt", new Vector2(100, 400), 40.0f, Texture_Button));
            Buttons.Add(
                new Button("Tilting Balls", new Vector2(300, 400), 40.0f, Texture_Button));
        }
        public override void Update(float fElapsedTime)
        {
            TouchCollection oCollection = TouchPanel.GetState();
            foreach (Button oButton in Buttons)
            {
                foreach (TouchLocation location in oCollection)
                {
                    if (Circle.ContainsPoint(oButton.Position, oButton.Radius, location.Position))
                    {
                        switch (oButton.Message)
                        {
                            case "Many Balls": GamePage.SetNextScreen(App.ScreenType.ManyBalls); break;
                            case "Aim It": GamePage.SetNextScreen(App.ScreenType.AimIt); break;
                            case "Putt Putt": GamePage.SetNextScreen(App.ScreenType.PuttPutt); break;
                            case "Tilting Balls": GamePage.SetNextScreen(App.ScreenType.TiltingBalls); break;
                        }
                    }
                }
            }
        }

        public override void Draw(float fElapsedTime)
        {
            SpriteBatch.Begin(SpriteSortMode.FrontToBack, null);

            foreach (Button oButton in Buttons)
            {
                oButton.Draw(SpriteBatch, Texture_Button, Font);
            }

            SpriteBatch.End();
        }

        #endregion

        #region Fields

        List<Button> Buttons
        {
            get;
            set;
        }

        SpriteFont Font
        {
            get;
            set;
        }

        public GamePage GamePage
        {
            get;
            protected set;
        }

        Texture2D Texture_Button;

        #endregion

    }
}
